package com.woniu.rules;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

import java.util.List;

public class MyRules extends AbstractLoadBalancerRule {
    public void initWithNiwsConfig(IClientConfig iClientConfig) {

    }
    int k=0;
    int p=1;
    public Server choose(Object o) {
        ILoadBalancer loadBalancer = this.getLoadBalancer();
        List<Server> allServers = loadBalancer.getAllServers();
        Server server = allServers.get(k);
        p++;
        if (p>5){
            k++;
            p=1;
        }

        if (k>allServers.size()-1){
            k=0;
        }
        return server;
    }
}
